package cn.itcast.mapreduce.covid.sortsum;

import cn.itcast.mapreduce.covid.bean.CovidCountBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class CovidSortSumReducer extends Reducer<CovidCountBean, Text, Text, CovidCountBean> {

    //排序好之后 reduce会进行分组操作  分组规则是判断key是否相等
    //本业务中 使用自定义对象作为key 并且没有重写分组规则 默认就会比较对象的地址  导致每个kv对自己就是一组
    //<CovidCountBean,加州> ---><CovidCountBean,Iterable[加州]>
    //<CovidCountBean,德州> ---><CovidCountBean,Iterable[德州]>
    @Override
    protected void reduce(CovidCountBean key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        Text outKey = values.iterator().next();//州
        context.write(outKey, key);
    }
}
